<?
/*
 * JuickDiff PHP
 * juick.php by Skobkin.ru
 * http://juick.com/skobkin-ru
*/

define ("juickurl", "http://juick.com/"); // main site URL

function GetHTML($url) // Get HTML code from URL
{
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects (fix bug with redirects)
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
$html = curl_exec($ch);
return $html;
}

function ParseFriends($html) // Parse friens of user to array
{
    $html = substr($html, strpos($html, "</h2><p>"));// Deleting all before "</h2><p>"
    $html = substr($html, 0, strpos($html, "</div>") - 5); // Deleting all afrer "</div>"
    /* Here there are two ways to implement tasks:
     * cutting tags and partitioning between commas,
     * or parsing the tags. */

    $html = strip_tags($html);
    $friends = explode(", ", $html);
    return $friends; // returns array of friend :-D
}

/*
function GetLines($filename) // Get array of users from file
{
    // Some questions about security, when opening files contenting usernames from _GET
    $file = file($filename);
    foreach($file as $line)
        if($line != "") // For last empty line
            $lines[] = $line; // Add new element to array
}
*/

function Diff($nowsub, $lastsub) // Find the difference between two username arrays
{
    $unsub = array_diff($lastsub, $nowsub); // Searching users not existing in new list
    for($i=0;$i<count($unsub);$i++)$unsub[$i]="-".$unsub[$i]; // Add "-" for each element
    $sub = array_diff($nowsub, $lastsub); // Searching users not existing in old list
    for($i=0;$i<count($sub);$i++)$sub[$i]="+".$sub[$i]; // Add "-" for each element
    return $unsub + $sub;
}

function LogAdd($text, $filename) // Append some text to log file
{
    
}

?>